
public class Date {

  private int year;
  private int month;
  private int day;

  public Date(int year, int month, int day) throws IllegalArgumentException {
    this.year = year;
    this.setMonth(month);
    this.setDay(day);
  }

  public Date(String date) {
    this(Integer.parseInt(date.split("-")[0]), Integer.parseInt(date.split("-")[1]), Integer.parseInt(date.split("-")[2]));
  }

  public int getDay() {
    return day;
  }

  public void setDay(int day) throws IllegalArgumentException {
    if (day < 1 || day > 31) {
      throw new IllegalArgumentException("Date : le jour doit être entre 1 et 31 (ici = " + day + ")");
    }
    this.day = day;
  }

  public int getMonth() {
    return month;
  }

  public void setMonth(int month) throws IllegalArgumentException {
    if (month < 1 || month > 12) {
      throw new IllegalArgumentException("Date : le mois doit être entre 1 et 31 (ici = " + month + ")");
    }
    this.month = month;
  }

  public int getYear() {
    return year;
  }

  public void setYear(int year) {
    this.year = year;
  }

  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    final Date other = (Date) obj;
    if (this.year != other.year) {
      return false;
    }
    if (this.month != other.month) {
      return false;
    }
    if (this.day != other.day) {
      return false;
    }
    return true;
  }

  public String toString() {
    return this.year + "-" + this.month + "-" + this.day;
  }
}
